﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsGameLibrary1;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Bipoland
{
    public class BackGround:Entity
    {
        private AnimationPlayer animationPlayer;
        private Vector2 position;
        private int index;
        public static int INDEX = 0;

        public Vector2 Position1
        {
            get { return position; }
            set { position = value; }
        }
        private float speed;
        private string path;
        public int direction;


        public BackGround(float speed, string path) 
        {
            animationPlayer = new AnimationPlayer();
            position = Vector2.Zero;
            this.speed = speed;
            this.path = path;
            direction = 0;
            index = INDEX++;
        }

        public void LoadContent(ContentManager Content)
        {

            Frame backg = new Frame();
            backg.Duration = 0.2f;
            backg.Origin = Vector2.Zero;
            backg.FlipOrigin = Vector2.Zero;
            backg.Sprite = Content.Load<Texture2D>(path);

            Animation backGround = new Animation();
            backGround.AnimationTime = 0.2f;
            backGround.SpriteCount = 1;
            backGround.AddFrame(backg);


            animationPlayer.AddAnimation(AnimationPlayerEnum.BACKGROUND,backGround);
            animationPlayer.ChangeAnimation(AnimationPlayerEnum.BACKGROUND,ModeEnum.Ever);
            animationPlayer.Play();
            animationPlayer.ColorFunction=White;
        }

        public void Update(GameTime gameTime)
        {
            position.X += (float)gameTime.ElapsedGameTime.TotalSeconds*speed * direction;
            direction = 0;
            animationPlayer.update(gameTime);

        }

        public void Draw(SpriteBatch spriteBatch, Microsoft.Xna.Framework.GameTime gameTime, float order, float scroller)
        {
            if (position.X < Game1.belmont.Position1.X + 1536 && position.X > Game1.belmont.Position1.X - 1536)
            {
                
                    animationPlayer.Draw(spriteBatch, gameTime, new Vector2(position.X - scroller - 30, position.Y), 1);
                
            }
            
        }

        public Vector2 Position()
        {
            return position;
        }

        public Vector2 ImageSize()
        {
            throw new NotImplementedException();
        }

        public void CollisionAction(Entity entity)
        {
            throw new NotImplementedException();
        }

        public BoundingBox CollisionRectangle()
        {
            throw new NotImplementedException();
        }

        public List<CollisionCoordinates> CollisionRectangles()
        {
            throw new NotImplementedException();
        }

        public float GivePaintOrder()
        {
            return 0;
        }

        public bool isdying()
        {
            return false;
        }

        public void ChangeBlack() 
        {
            animationPlayer.ColorFunction = Black;
        }

        public void ChangeWhite()
        {
            animationPlayer.ColorFunction = White;
        }

        public Color Black(Color color, GameTime gametime)
        {
            color = Color.Black;
            return color;
        }

        public Color White(Color color, GameTime gametime)
        {
            color = Color.White;
            return color;
        }
    }
}
